﻿using aier.business.logic;
using aier.dataaccess.model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.Http;

namespace aier.wx.api.selfhost.Controllers
{
    //[Authorize]
    [RoutePrefix("api/Category")]
    public class CategoryController :ApiController
    {
        public CategoryBll categoryBll { get; set; }
        /// <summary>
        /// 获取所有项目
        /// 原程序 ScCategoryServiceImpl/getAll
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        [ActionName("GetAllCategoryInfo")]
        public IHttpActionResult GetAllCategoryInfo()
        {
            List<CategoryView> categoryViews = null;
            categoryViews = categoryBll.GetAllCategoryInfo();
            return Ok<List<CategoryView>>(categoryViews);
        }

        /// <summary>
        /// 根据项目ID获取项目
        /// 查询条件：项目ID
        /// 原程序 ScCategoryServiceImpl/getById
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        [ActionName("GetCategoryInfoById")]
        public IHttpActionResult GetCategoryInfoById(string CategoryId)
        {
            CategoryView categoryView = null;
            categoryView = categoryBll.GetCategoryInfoById(CategoryId);
            return Ok<CategoryView>(categoryView);
        }


        [HttpGet]
        [ActionName("GetCategorIdByTmeplateId")]
        public IHttpActionResult GetCategorIdByTmeplateId(string templateId)
        {
            try
            {
                if (string.IsNullOrWhiteSpace(templateId))
                {
                    return new ApiErrorResult("筛查模版id不能为空", Request);
                }

                var templates = categoryBll.GetCategorIdByTmeplateId(new Guid(templateId));
                return Ok(templates);
            }
            catch (Exception ex)
            {
                //log.Error(ex.Message, ex);
                return new ApiErrorResult(ex.Message, Request);

            }
        }
    }
}
